﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default4 : System.Web.UI.Page
{
    AccesoDatos datos = new AccesoDatos();
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        datos.LlenarDataset("Select Nombre from Tragos", "Tragos", ref ds);
        gvTragos.DataSource = ds;
        gvTragos.DataBind();
    }
    protected void gvBebidas_SelectedIndexChanged(object sender, EventArgs e)
    {
        string Codigo;
        GridView gvNew = new GridView();
        datos.LlenarDataset("Select * from Tragos", "Tragos", ref ds);
        gvNew.DataSource = ds;
        gvNew.DataBind();
        Codigo = gvNew.Rows[gvTragos.SelectedIndex].Cells[0].Text;

         //   [0,gvTragos.SelectedIndex].Value.ToString().Trim();
        lstIngredientes.Items.Clear();
        SqlConnection connection = new SqlConnection();
        SqlCommand SQLcmd = new SqlCommand();
        connection.ConnectionString = "Data Source=localhost;Initial Catalog=Final;Integrated Security=True";
        SQLcmd.Connection = connection;
        SQLcmd.CommandType = CommandType.Text;

        //if (rbArticulos.Checked == true)
        //{
        //    SQLcmd.CommandText = "select distinct marcas.nombre from (articulos inner join artxprov on artxprov.codart = articulos.codart) inner join marcas on marcas.codmarca = artxprov.codmarca WHERE articulos.nombre = " + "'" + Codigo + "'";
        //}
        //if (rbProveedores.Checked == true)
        //{
        //    SQLcmd.CommandText = "select distinct articulos.nombre from (articulos inner join artxprov on artxprov.codart = articulos.codart) inner join proveedores on proveedores.codprov = artxprov.codprov WHERE proveedores.nombre = " + "'" + Codigo + "'";
        //}
        //if (rbTragos.Checked == true)
        //{
        SQLcmd.CommandText = "select distinct artxtrago.cantidad + ' ' +  articulos.nombre from (articulos inner join artxtrago on artxtrago.codart = articulos.codart) inner join tragos on tragos.codt=artxtrago.codt WHERE tragos.nombre = " + "'" + Codigo + "'";
        //}
        connection.Open();
        SqlDataReader dr = SQLcmd.ExecuteReader();
        while (dr.Read())
        {
            lstIngredientes.Items.Add(dr[0].ToString().Trim());
        }
        connection.Close();  
    }
}